<template>
  <div class="wrap">
    <div class="image-wrap">
      <img src="@/assets/image/advanced.png" alt="" />
    </div>
    <div class="search-cate">
      <label>检索分类</label>
      <el-popover
        title="选择分类"
        placement="bottom"
        width="300"
        trigger="manual"
        v-model="selectVisible"
      >
        <div class="trees-wrap">
          <el-tree
            :data="treeData"
            :props="defaultProps"
            @node-click="handleNodeClick"
          />
          <div
            style="margin-top: 20px; display: flex; justify-content: flex-end"
          >
            <el-button type="primary" size="mini" @click="selectConfirm"
              >确认</el-button
            >
            <el-button size="mini" @click="selectCancel">取消</el-button>
          </div>
        </div>
        <div class="input-box" slot="reference" @click="selectVisible = true">
          {{ selectLabel ? selectLabel : "请选择分类" }}
        </div>
      </el-popover>
    </div>
  </div>
</template>

<script>
export default {
  name: "searchCate",
  props: ["treeData"],
  data() {
    return {
      selectVisible: false,

      defaultProps: {
        children: "children",
        label: "label",
      },
      selectLabel: "",
      sortItem: "",
    };
  },
  methods: {
    handleNodeClick(data) {
      // console.log(44,data)
      this.sortItem = data;
      this.selectLabel = data.label;
    },
    // 选择分类确认
    selectConfirm() {
      this.selectVisible = false;
      this.$emit("loadFilterLabel", this.sortItem);
    },
    // 选择分类取消
    selectCancel() {
      this.selectLabel = "";
      this.selectVisible = false;
    },
  },

  watch: {
    selectLabel: {
      immediate: true,
      handler(val) {
        this.$bus.$emit("getInputValue", val);
      },
    },
  },
};
</script>

<style lang="scss" scoped>
.wrap {
  position: relative;
  .image-wrap {
    position: absolute;
    top: 0;
    left: calc(50% - 400px);
    z-index: -1;
    width: 800px;
    .text {
      position: absolute;
      font-size: 60px;
      top: 0;
      left: 50%;
      top: 120px;
    }
  }
  .search-cate {
    display: flex;
    justify-content: center;
    margin-top: 300px;
    > label {
      font-size: 36px;
      color: #333;
      padding-right: 20px;
      line-height: 50px;
      font-weight: 400;
    }
    .input-box {
      width: 526px;
      height: 50px;
      border: 1px solid #999;
      border-radius: 5px;
      color: rgb(185,185,185);
      line-height: 50px;
      font-size: 24px;
      padding-left: 10px;
      cursor: pointer;
    }
  }
}
</style>
